{include file="public/header"}
<body>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-search" v-if="1===2">
            <el-form :inline="true" size="small">
                <el-form-item label="标识" >
                    <el-input placeholder="标识" v-model="searchKey.flag"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
                    <el-button type="" icon="el-icon-refresh" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="ht-tool">
            <div class="ht-tool-left">
                <el-button type="success" size="mini" icon="el-icon-plus" @click="doAdd">添加</el-button>
                <el-button type="primary" :disabled="tableSelect.length !== 1" size="mini" icon="el-icon-edit" @click="edit(tableSelect[0])">编辑</el-button>
                <el-button type="danger" :disabled="!tableSelect.length" size="mini" icon="el-icon-delete" @click="batchDel('/admin/banner/bannerDel')">删除</el-button>
            </div>
        </div>
        <div class="ht-main-body">
            <el-table :data="tableData" border @selection-change="handleSelectChange" header-row-class-name="ht-table-header">
                <el-table-column type="selection"></el-table-column>
                <el-table-column
                        align="center"
                        prop="id"
                        label="ID">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="image"
                        label="图片">
                    <template slot-scope="scope">
                        <el-image @click="showImg(scope.row.image)" :src="scope.row.image" style="max-width: 100px"></el-image>
                    </template>
                </el-table-column>
               <el-table-column
                       align="center"
                       prop="flag"
                       label="平台">
                   <template slot-scope="scope">
                       <span v-if="scope.row.flag == 'pc'">pc</span>
                       <span v-else>小程序</span>
                   </template>
               </el-table-column>
                <el-table-column
                        align="center"
                        prop="bz"
                        label="备注">
                </el-table-column>

                <el-table-column
                        align="center"
                        prop="status"
                        label="状态">
                    <template slot-scope="scope">
                        <el-switch v-model="scope.row.status"
                                   active-color="#13ce66"
                                   inactive-color="#eeeeee"
                                   @change="changeStatus($event,scope.row.id)"
                                   :active-value="2"
                                   :inactive-value="1">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="sort"
                        label="排序">
                </el-table-column>
                <el-table-column align="center"
                                 prop="create_time"
                                 label="发布时间">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="操作">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row)" size="small" type="primary" icon="el-icon-edit"></el-button>
                        <el-button @click="del(scope.row)" size="mini" type="danger" icon="el-icon-delete"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="ht-main-page">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page"
                        :page-sizes="[1,10, 200, 300, 400]"
                        :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <el-drawer
                    :visible.sync="is_edit"
                    size="90%"
                    :with-header="false"
                    custom-class="ht-drawer-bg"
            >
                <div class="ht-drawer-main">
                    <el-page-header @back="goBack" title="Esc返回" :content="content"></el-page-header>
                    <div class="ht-form">
                        <el-form :model="editData" size="small" label-width="80px">
                            <el-form-item label="图片">
                                <el-input placeholder="图片" v-model="editData.image"
                                          style="width: 50%"></el-input>
                                <el-button  @click="imageOpen()" type="primary">选择</el-button>
                                <div class="ht-text">710*280 等比</div>
                            </el-form-item>
                            <el-form-item v-if="editData.image">
                                <el-image :src="editData.image" class="ht-image100" @click="showImg(editData.image)"></el-image>
                            </el-form-item>
                            <el-form-item label="排序">
                                <el-input placeholder="排序" v-model="editData.sort"
                                          style="width: 50%"></el-input>
                            </el-form-item>
                           <el-form-item label="平台">
                               <el-select v-model="editData.flag">
                                   <el-option value="wx" label="小程序"></el-option>
                               </el-select>
                           </el-form-item>
                            <el-form-item label="备注">
                                <el-input placeholder="备注" v-model="editData.bz" type="textarea"
                                          style="width: 50%"></el-input>
                            </el-form-item>

                            <el-form-item>
                                <el-button @click="goBack">取消</el-button>
                                <el-button type="primary" @click="onSubmit">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-drawer>

        </div>

    </div>
</div>


{include file="public/common"}
<script>
    let vs ;
    let del_url = "{:url('Banner/del')}";
    let add_url = "{:url('Banner/add')}";
    let index_url = "{:url('Banner/index')}";
    var vm = new Vue({
        el: "#app",
        data: function () {
            return {
                arctypeList: [],
                activeTab: 'first',
                tableData: [],
                is_edit: false,
                editData: {
                    "status": 1,
                    "litpic": '',
                    "bz": "",
                    "flag": "",
                    "sort":0,
                    is_video:0
                },
                editDataTemp: {
                    "status": 1,
                    "litpic": '',
                    "bz": "",
                    "flag": "",
                    "sort":0,
                    is_video:0
                },
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                search_arctype_id: "",
                search_title: "",
                editBody: '13123',
                pre_view: [],
                isshow:false,
                searchType:{},
                searchKey:{}
            }
        },
        created: function () {
            vs = this
            this.getData()
        },
        methods: {
            showUpload(){
                this.isshow = true
            },
            uploadSuccess(path) {
                this.isshow = false
                this.editData.litpic = path
            },
            changeStatus: function (e, id) {
                $.post("{:url('Banner/bannerStatus')}", {id: id}).then((res) => {
                    if (res.code == 1) {
                        vs.showSuccessMsg()
                    } else {
                        vs.showErrorMsg(res.msg)
                    }
                })
            },
            doSearch: function () {
                this.getData()
            },
            onSubmit() {
                $.post('{:url("Banner/add")}', vs.editData, function (res) {
                    if (res.code == 1) {
                        vs.showSuccessMsgCall(function () {
                            location.reload();
                        })
                    } else {
                        vs.showErrorMsg(res.msg)
                    }
                })

            },
            getData: function () {
                vs.searchType = {
                    title: 'like'
                };
                $.post(index_url, {
                    limit: vs.limit,
                    page: vs.page,
                    search_key: vs.searchKey,
                    search_type: vs.searchType
                }, function (res) {
                    if (res.code == 1) {
                        vs.tableData = res.data.data
                        vs.total = res.data.total
                    } else {
                        vs.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = this.editDataTemp
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data
                console.log(data)
            },
            goBack: function () {
                this.is_edit = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    axios.post('{:url("Banner/BannerDel")}', {id: data.id}).then((res) => {
                        let result = res.data;
                        if (result.code === 1) {
                            that.showSuccessMsgCall(function () {
                                location.reload()
                            })
                        } else {
                            that.showErrorMsg(result.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
